using System;
using System.Collections.Generic;
using System.Text;

namespace CddSharp
{
    public partial class Cdd
    {
        /* cddmp.c       (cddlib arithmetic operations using gmp)
           Copyright: Komei Fukuda 2000, fukuda@ifor.math.ethz.ch
           Version 0.94, Aug. 4, 2005
        */
        /* This program is free software; you can redistribute it and/or modify
           it under the terms of the GNU General Public License as published by
           the Free Software Foundation; either version 2 of the License, or
           (at your option) any later version.

           This program is distributed in the hope that it will be useful,
           but WITHOUT ANY WARRANTY; without even the implied warranty of
           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           GNU General Public License for more details.

           You should have received a copy of the GNU General Public License
           along with this program; if not, write to the Free Software
           Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
         */

        public void set_global_constants()
        {
            statStartTime = DateTime.Now; /* cddlib starting time */
            statBApivots = 0;  /* basis finding pivots */
            statCCpivots = 0;  /* criss-cross pivots */
            statDS1pivots = 0; /* phase 1 pivots */
            statDS2pivots = 0; /* phase 2 pivots */
            statACpivots = 0;  /* anticycling (cc) pivots */

            choiceLPSolverDefault = LPSolverType.DualSimplex;  /* Default LP solver Algorithm */
            choiceRedcheckAlgorithm = LPSolverType.DualSimplex;  /* Redundancy Checking Algorithm */
            choiceLexicoPivotQ = true;    /* whether to use the lexicographic pivot */

#if nemkell
//#if GMPRATIONAL
 statBSpivots=0;  /* basis status checking pivots */
 mpq_set_ui(zero,0U,1U);
 mpq_set_ui(purezero,0U,1U);
 mpq_set_ui(one,1U,1U);
 mpq_set_si(minusone,-1L,1U);
 ddf_set_global_constants();
//#elif GMPFLOAT
 mpf_set_d(zero,almostzero);
 mpf_set_ui(purezero,0U);
 mpf_set_ui(one,1U);
 mpf_set_si(minusone,-1L,1U);
//#else
 zero[0]= 0;  /*real zero */
 purezero[0]= 0.0;
 one[0]= 1L;
 minusone[0]= -1L;
//#endif
 neg(minuszero,zero);
#endif
        }

#if nemkell
//#if GMPRATIONAL
void dmpq_set_si(mytype a,signed long b)
{
  mpz_t nz, dz;

  mpz_init(nz); mpz_init(dz);

  mpz_set_si(nz, b);
  mpz_set_ui(dz, 1U);
  mpq_set_num(a, nz);
  mpq_set_den(a, dz);
  mpz_clear(nz);  mpz_clear(dz);
}
//#endif

//#if defined CDOUBLE
void dinit(mytype a)   
{
  a[0]=0L;
}
  
void dclear(mytype a)
{
  /* a[0]=0L;  */
}

void dset(mytype a,mytype b)
{
  a[0]=b[0];
}

void dset_d(mytype a,double b)
{
  a[0]=b;
}

void dset_si(mytype a,signed long b)
{
  a[0]=(double)b;
}

void dset_si2(mytype a,signed long b, unsigned long c)
{
  a[0]=(double)b/(double)c;
}

void dadd(mytype a,mytype b,mytype c)
{
  a[0]=b[0]+c[0];
}

void dsub(mytype a,mytype b,mytype c)
{
  a[0]=b[0]-c[0];
}

void dmul(mytype a,mytype b,mytype c)
{
  a[0]=b[0]*c[0];
}

void ddiv(mytype a,mytype b,mytype c)
{
  a[0]=b[0]/c[0];
}

void dneg(mytype a,mytype b)
{
  a[0]=-b[0];
}

void dinv(mytype a,mytype b)
{
  a[0]=1/b[0];
}

int dcmp(mytype a,mytype b)
{
  if (a[0]-b[0]>0) return 1;
  else if (a[0]-b[0]>=0) return 0;
  else return -1;
}

int dsgn(mytype a)
{
  if (a[0]>0) return 1;
  else if (a[0]>=0) return 0;
  else return -1;
}

double dget_d(mytype a)
{
  return a[0];
}
#endif

        /* end of  cddmp.h  */

    }
}
